import request from '@/utils/request';

export function login(data) {
  return request({
    url: '/admin/login',
    // url: '/txs/common',
    method: 'post',
    data,
  });
}

export function logoutById(id) {
  return request({
    url: '/admin/logout/' + id,
    method: 'get',
  });
}

export function assignedBranch(sid) {
  return request({
    url: '/admin/branched/' + sid,
    method: 'get',
  });
}

export function getInfo() {
  return request({
    url: '/admin/token',
    // url: '/txs/common',
    method: 'get',
  });
}

export function getTokenDirector(sid) {
  return request({
    url: '/admin/token/director/' + sid,
    method: 'get',
  });
}

export function getTokenKeeper(sid) {
  return request({
    url: '/admin/token/keeper/' + sid,
    method: 'get',
  });
}

export function changePwd(data) {
  return request({
    url: '/admin/changepwd',
    method: 'post',
    data,
  });
}

export function register(data) {
  return request({
    url: '/admin',
    method: 'post',
    data,
  });
}

export function delAdmin(id) {
  return request({
    url: '/admin/' + id,
    method: 'delete',
  });
}

export function editAdmin(data) {
  return request({
    url: '/admin',
    method: 'put',
    data,
  });
}

export function changeFrozen(id, data) {
  return request({
    url: '/admin/froze/' + id,
    method: 'put',
    data,
  });
}

export function countBySalons(data) {
  return request({
    url: '/admin/count/salons',
    method: 'put',
    data,
  });
}

export function getAdmins(pageNumber, pageSize, sids) {
  return request({
    url: '/admin',
    method: 'get',
    params: { pageNumber, pageSize, sids },
  });
}

/**
 * 分页查询用户
 *
 * @param {Object} params
 * @return {Promise}
 */
export function getUserPage(params) {
  return request({
    url: '/admin',
    method: 'get',
    params: params,
  });
}

export function getSomeAdmins(sname, uname, sids) {
  return request({
    url: '/admin/some',
    method: 'get',
    params: { sname, uname, sids },
  });
}

export function getAdminsByDuties(did, pageNumber, pageSize, mid, role) {
  return request({
    url: '/admin/duties/' + did,
    method: 'get',
    params: { pageNumber, pageSize, mid, role },
  });
}

export function someAdminsByDuties(did, mid, role, sname, uname) {
  return request({
    url: '/admin/dutiesome/' + did,
    method: 'get',
    params: { mid, role, sname, uname },
  });
}

export function setStar(id, detail, star) {
  return request({
    url: '/admin/star/' + id,
    method: 'get',
    params: { detail, star },
  });
}

export function getKeepsBySid(sid) {
  return request({
    url: '/admin/salon/' + sid,
    method: 'get',
  });
}

export function getAdminsByRole(role) {
  return request({
    url: '/admin/role/' + role,
    method: 'get',
  });
}

export function getAdminsBySid(sid) {
  return request({
    url: '/admin/plan/' + sid,
    method: 'get',
  });
}

export function statPlanMoneyBySid(sid) {
  return request({
    url: '/admin/stat/' + sid,
    method: 'get',
  });
}

export function statMonthPlanMoney() {
  return request({
    url: '/admin/stat',
    method: 'get',
  });
}

export function changePlanBySid(data) {
  return request({
    url: '/admin/plan',
    method: 'put',
    data,
  });
}

export function getAdminById(id) {
  return request({
    url: '/admin/keeper/' + id,
    method: 'get',
  });
}

/**
 * @deprecated 这是一个不成熟的接口, 无需调用(管家的交易记录都记录在 business 表中)
 * @param {number} kid
 * @param {Object} data
 * @return {Promise}
 */
export function updateKeeperMoney(kid, data) {
  return request({
    url: '/admin/money/' + kid,
    method: 'put',
    data,
  });
}

/**
 * 根据门店 id, 查询属于该门店的所有管家
 * @param {number} sid 门店主键ID
 * @return {Array}
 */
export function getKeepersBySid(sid) {
  return request({
    url: '/admin/list/all/keepers',
    method: 'get',
    params: { sid },
  });
}
